package com.minimalist.basic.controller.lindi;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.enterpriseregistration.LindiEnterpriseRegistrationAuditVO;
import com.minimalist.common.entity.lindi.vo.enterpriseregistration.LindiEnterpriseRegistrationQueryVO;
import com.minimalist.common.entity.lindi.vo.enterpriseregistration.LindiEnterpriseRegistrationVO;
import com.minimalist.common.feign.client.lindi.LindiEnterpriseRegistrationFeignClient;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_企业注册管理")
@RequestMapping("/basic/lindi/enterpriseRegistration")
public class LindiEnterpriseRegistrationController{

    @Autowired
    private LindiEnterpriseRegistrationFeignClient feignClient;

    @PostMapping("/addEnterpriseRegistration")
    @SaCheckPermission("lindi:enterpriseRegistration:add")
    @Operation(summary = "添加企业注册信息")
    public R<?> addEnterpriseRegistration(
            @RequestBody @Validated(Add.class)
            LindiEnterpriseRegistrationVO enterpriseRegistrationVO){
        enterpriseRegistrationVO.setCreateId(StpUtil.getLoginIdAsLong());
        enterpriseRegistrationVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        enterpriseRegistrationVO.setCreateTime(now);
        enterpriseRegistrationVO.setUpdateTime(now);
        return feignClient.addEnterpriseRegistration(enterpriseRegistrationVO);
    }

    @DeleteMapping("/deleteEnterpriseRegistrationByEnterpriseRegistrationId")
    @SaCheckPermission("lindi:enterpriseRegistration:delete")
    @Operation(summary = "删除企业注册信息 -> 根据企业注册信息ID删除")
    public R<?> deleteEnterpriseRegistrationByEnterpriseRegistrationId(
            @RequestParam("enterpriseRegistrationId")
            @NotNull(message = "企业注册信息ID不能为空")
            @Parameter(name = "enterpriseRegistrationId", required = true
                    , description = "企业注册信息ID") Long enterpriseRegistrationId){
        return feignClient.deleteEnterpriseRegistrationByEnterpriseRegistrationId(enterpriseRegistrationId);
    }

    @PutMapping("/updateEnterpriseRegistrationByEnterpriseRegistrationId")
    @SaCheckPermission("lindi:enterpriseRegistration:update")
    @Operation(summary = "修改企业注册信息")
    public R<?> updateEnterpriseRegistrationByEnterpriseRegistrationId(
            @RequestBody @Validated(Update.class)
            LindiEnterpriseRegistrationVO enterpriseRegistrationVO){
        enterpriseRegistrationVO.setCreateId(StpUtil.getLoginIdAsLong());
        enterpriseRegistrationVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        enterpriseRegistrationVO.setCreateTime(now);
        enterpriseRegistrationVO.setUpdateTime(now);
        return feignClient.updateEnterpriseRegistrationByEnterpriseRegistrationId(enterpriseRegistrationVO);
    }

    @GetMapping("/getPageEnterpriseRegistrationList")
    @SaCheckPermission("lindi:enterpriseRegistration:get")
    @Operation(summary = "查询企业注册信息列表(分页)")
    public R<PageResp<LindiEnterpriseRegistrationVO>>
    getPageEnterpriseRegistrationList(LindiEnterpriseRegistrationQueryVO queryVO){
        return feignClient.getPageEnterpriseRegistrationList(queryVO);
    }

    @GetMapping("/getEnterpriseRegistrationByEnterpriseRegistrationId/{enterpriseRegistrationId}")
    @SaCheckPermission("lindi:enterpriseRegistration:get")
    @Operation(summary = "根据企业注册信息ID查询企业注册信息")
    public R<LindiEnterpriseRegistrationVO> getEnterpriseRegistrationByEnterpriseRegistrationId(
            @PathVariable(value = "enterpriseRegistrationId")
            @NotNull(message = "企业注册信息ID不能为空")
            @Parameter(name = "enterpriseRegistrationId", description = "参数ID"
                    , required = true) Long enterpriseRegistrationId){
        return feignClient.getEnterpriseRegistrationByEnterpriseRegistrationId(enterpriseRegistrationId);
    }

    @PostMapping("/auditEnterpriseRegistration")
    @SaCheckPermission("lindi:enterpriseRegistration:audit")
    @Operation(summary = "审核企业注册信息")
    public R<?> auditEnterpriseRegistration(
            @RequestBody @Validated(Update.class)
            LindiEnterpriseRegistrationAuditVO auditVO){
        return feignClient.auditEnterpriseRegistration(auditVO);
    }
}